#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2020/3/25  10:01
# @Author: 余浪人
# @email: yulangren520@gmail.com

import redis, json
from api import r


class MyDB():
    def __init__(self):
        self._r = r

    # 国内池
    def save_inland(self, ip: str, port: str):
        try:
            port = int(port.strip())
        except:
            return
        self._r.hset('raw_pool_inland', f'{ip.strip()}:{port}', json.dumps({'ip': ip.strip(), 'port': port}))

    # 国外池
    def save_foreign(self, ip: str, port: str):
        try:
            port = int(port.strip())
        except:
            return
        self._r.hset('raw_pool_foreign', f'{ip.strip()}:{port}', json.dumps({'ip': ip.strip(), 'port': port}))

    # def __del__(self):
    #     self._r.close()